/**
 * 作者:hanbo
 * 日期:2018/11/2117:01
 * 描述:矩形
 */
import {Geometry} from "./Geometry";
import {BoundingBox} from "./BoundingBox";
import {PolygonStyle} from "./style/PolygonStyle";

export class Rectangle extends Geometry{
    constructor(xMin = 0, yMin = 0, xMax = 0, yMax = 0) {
        super("rectangle",new BoundingBox([xMin,yMin,xMax,yMax]));
        this.xMin = xMin;
        this.yMin = yMin;
        this.xMax = xMax;
        this.yMax = yMax;
    }

    /**
     * 设置样式
     * @param polygonStyle {PolygonStyle} 面样式
     */
    setStyle(polygonStyle){
        this.style=polygonStyle
    }

    /**
     * 获取多边形样式
     * @returns {PolygonStyle} 若无样式，范围默认样式
     */
    getStyle(){
        if(this.style){
            return this.style;
        }else {
           return new PolygonStyle()
        }
    }

    /**
     * 判断两个矩形是否相交
     * @param rectangle1 {Rectangle} 矩形1
     * @param rectangle2 {Rectangle} 矩形2
     */
    static isIntersect(rectangle1, rectangle2) {
        if (rectangle1.xMin > rectangle2.xMax ||
            rectangle1.yMin > rectangle2.yMax ||
            rectangle2.xMin > rectangle1.xMax ||
            rectangle2.yMin > rectangle1.yMax) {
            return false
        } else {
            return true
        }
    }
}